package com.cloudeasy.post.client;

import com.cloudeasy.api.enums.ResultCodeEnum;
import com.cloudeasy.api.util.ResultUtil;
import com.cloudeasy.api.vo.Result;
import com.cloudeasy.api.vo.label.LabelVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@CrossOrigin
@FeignClient(value = "cloudeasy-label", fallback = LabelClient.LabelClientFallback.class)
public interface LabelClient {
    /**
     * 获取某用户关注的标签
     *
     * @param userId 用户Id
     * @return {@link List < LabelVO >}的{@link Result}
     */
    @GetMapping("/attention/user/{userId}")
    Result<List<LabelVO>> getAttention(@PathVariable("userId") String userId);

    /**
     * 查询标签
     *
     * @param ids      标签Id列表
     * @param names    标签名称列表
     * @param statuses 状态列表
     * @param asc      正序排序字段
     * @param desc     倒序排序字段
     * @return {@link List<LabelVO>}的{@link Result}
     */
    @GetMapping("/")
    Result<List<LabelVO>> list(@RequestParam(value = "ids", required = false) List<String> ids,
                                      @RequestParam(value = "names", required = false) List<String> names,
                                      @RequestParam(value = "statuses", required = false) List<String> statuses,
                                      @RequestParam(value = "asc", required = false) String[] asc,
                                      @RequestParam(value = "desc", required = false) String[] desc);

    @Component
    static class LabelClientFallback implements LabelClient {
        @Override
        public Result<List<LabelVO>> getAttention(String userId) {
            return ResultUtil.failure(ResultCodeEnum.REMOTE_ERROR);
        }

        @Override
        public Result<List<LabelVO>> list(List<String> ids, List<String> names, List<String> statuses, String[] asc, String[] desc) {
            return ResultUtil.failure(ResultCodeEnum.REMOTE_ERROR);
        }
    }
}
